package sd.czw.com.miemiegoushop.activity;

import android.support.v4.util.ArrayMap;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.model.Response;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import sd.czw.com.miemiegoushop.R;
import sd.czw.com.miemiegoushop.adapter.MyPullAdapter;
import sd.czw.com.miemiegoushop.base.CzwBaseActivity;
import sd.czw.com.miemiegoushop.data.Contants;
import sd.czw.com.miemiegoushop.data.GoodsModelk;
import sd.czw.com.miemiegoushop.ui.MyCallBak;

/**
 * Created by czw
 * desc 描述：
 * on 2017/10/11.
 */
public class GrideManagerActivity extends CzwBaseActivity {

    private RecyclerView recyclerView;
    private MyPullAdapter myPullAdapter;
    private List<GoodsModelk.ErrmsgBean> data = new ArrayList<>();
    private Map<String,String> params = new ArrayMap<>();
    private int start = 0;
    private int page = 0;


    @Override
    public int getLayoutId() {
        return R.layout.activity_gridmanager;
    }

    @Override
    public void initView() {
        StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        myPullAdapter = new MyPullAdapter(R.layout.item_stager,data);
        recyclerView.setAdapter(myPullAdapter);
        recyclerView.setLayoutManager(manager);
        lodatas();
    }

    private void lodatas() {
        params.put("time", Contants.Time);
        params.put("sign", Contants.Sign);
        params.put("start", String.valueOf(start));
        params.put("limit", "20");
        OkGo.<GoodsModelk>post("http://miemiegou.com/wap/app_index_getgoods.php")
                .cacheMode(CacheMode.REQUEST_FAILED_READ_CACHE)
                .cacheTime(3600 * 1000)
                .params(params)
                .execute(new MyCallBak<GoodsModelk>(GoodsModelk.class, this) {

                    @Override
                    public void onSuccess(Response<GoodsModelk> response) {
                        if (response.body().getErrcode() == 1) {
                            data.addAll(response.body().getErrmsg());
                            myPullAdapter.notifyDataSetChanged();
                        }
                    }

                    @Override
                    public void onError(Response<GoodsModelk> response) {

                    }
                });
    }

    @Override
    public void initData() {

    }
}
